package com.syxp.pda.core.xls;

import java.io.File;
import java.util.List;

import org.apache.struts2.ServletActionContext;

import jxl.Workbook;
import jxl.write.Label;
import jxl.write.WritableSheet;
import jxl.write.WritableWorkbook;

import com.syxp.pda.core.util.XlsBuilder;

public class WorkReport extends XlsBuilder{

	@Override
	public void xlsBuilder(TitleInfoBean title ,List<String[]> list) throws Exception{
		String fpath = ServletActionContext.getServletContext().getRealPath("temp/"+title.getFileName());
		WritableWorkbook workbook = Workbook.createWorkbook(new File(fpath)) ;
		WritableSheet sheet = workbook.createSheet(title.getFileName(), 0) ;
		for(int i=0; i<title.getTitleInfo().length; i++) {
			Label label = new Label(i, 0, title.getTitleInfo()[i]);
			sheet.addCell(label);
		}
		for(int y=1; y<=list.size(); y++) {
			String[] cont = list.get(y-1);
			for(int x=0; x<cont.length; x++) {
				Label label = new Label(x, y, cont[x]);
				sheet.addCell(label);
			}
		}
		workbook.write() ;
		workbook.close();
	}
	

}
